<%--
  Created by IntelliJ IDEA.
  User: 10175
  Date: 2019/7/3
  Time: 15:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

    <script >
        var path = '${pageContext.request.contextPath }';
        console.log(path);
        $(document).ready(function () {
            $.get(path + '/addShopcar', {method: "showshopcar"}, function (data) {
                arr = data[0];
                num=arr.length;
                $('#pnum').text(num);
                arr.forEach(function (item,index) {
                    $("div[id='row_id']").append("  <div class=\"cart-block cart-block-item clearfix\">\n" +
                        "                    <div class=\"image\">\n" +
                        "                        <a href=\"product.jsp\"><img src=\"${pageContext.request.contextPath}/"+item.pic+"\"\n" +
                        "                                                   alt=\"\"/></a>\n" +
                        "                    </div>\n" +
                        "                    <div class=\"title\">\n" +
                        "                        <div style=\"font-size: small\"><a href=\"product.jsp\">"+item.goodsName+"</a></div>\n" +
                        "\n" +
                        "                    </div>\n" +
                        "                    <div class=\"quantity\">\n" +
                        "                        <input type=\"checkbox\" class=\"shopcar\" id=\"gcid_"+index+"\" name=\"gcid\" value=\"1\">\n" +
                        "                        <input type=\"number\" value=\""+ item.nums +       "\" class=\"form-control form-quantity num\" id=\"num_1\"/>\n" +
                        "                    </div>\n" +
                        "                    <div class=\"price\">\n" +
                        "                        <span class=\"final\" style=\"font-size: small\">"+item.price+"</span>\n" +
                        "                        <span class=\"yuan\" style=\"display:none\">"+item.ID+"</span>\n" +
                         "                         </div>\n" +
                        "\n" +
                        "                <span class=\"icon icon-cross icon-delete\"> </span>");

                });

                var script = document.createElement('script');
                script.setAttribute("src","${pageContext.request.contextPath}/js/shopcar.js");
                $('head').append(script);


            },'json');
        });

    </script>


</head>
<body>
<div class="cart-wrapper">
    <div class="checkout">
        <div class="clearfix">


            <span class="icon icon-cross icon-delete" onclick="deleteshopcar(item.id)"> </span>

            <!--cart item-->

            <div class="row" id="row_id">
                <div class="cart-block cart-block-item clearfix" style="width: 278px;height: 36px">
                    <input type="checkbox" class="selectall-shopcar" id="selectall"> <span>全选</span>
                </div>
            </div>
            <hr/>
            <!--cart final price -->

            <div class="clearfix">
                <div class="cart-block cart-block-footer clearfix">
                    <div>
                        <strong>Total</strong>
                    </div>
                    <div>
                        <span class="h5 title" id="totalprice">0</span>
                    </div>
                </div>
            </div>
            <!--cart navigation -->
            <div class="cart-block-buttons clearfix">
                <div class="row">
                    <div class="col-xs-6">
                        <a href="${pageContext.request.contextPath}/GoodsServlet?method=ishot" class="btn btn-clean-dark">再逛逛</a>
                    </div>
                    <div class="col-xs-6 text-right">
                        <a onclick="check()" class="btn btn-main"><span class="icon icon-cart"></span>去支付</a>
                    </div>
                </div>
            </div>
        </div>
    </div> <!--/checkout-->
</div>
</body>
<script>
    function check() {
        alert(name);
        if(${name!=null}){
            location.href = "${pageContext.request.contextPath}/html/submit.jsp";
        }else {
            alert("请先登录！");
            location.href = "${pageContext.request.contextPath}/GoodsServlet?method=ishot";
        }
    }
</script>
</html>



